home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cfengine-1.5.3 / pub / full-write.c next >
Encoding:
C/C++ Source or Header  |  1997-07-10  |  1.6 KB  |  65 lines

  1. /* full-write.c -- an interface to write that retries after interrupts
  2.    Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.    Copied largely from GNU C's cccp.c.
  19.    */
  20.  
  21.  
  22. #include "../src/conf.h"
  23. #include <sys/types.h>
  24.  
  25. #ifdef HAVE_UNISTD_H
  26. #include <unistd.h>
  27. #endif
  28. #include <errno.h>
  29. #ifndef STDC_HEADERS
  30. extern int errno;
  31. #endif
  32.  
  33. /* Write LEN bytes at PTR to descriptor DESC, retrying if interrupted.
  34.    Return LEN upon success, write's (negative) error code otherwise.  */
  35.  
  36. cf_full_write (desc, ptr, len)
  37.  
  38. int desc;
  39. char *ptr;
  40. size_t len;
  41.  
  42. { int total_written;
  43.  
  44. total_written = 0;
  45.  
  46. while (len > 0)
  47.    {
  48.    int written = write (desc, ptr, len);
  49.    
  50.    if (written < 0)
  51.       {
  52.       if (errno == EINTR)
  53.          {
  54.          continue;
  55.          }
  56.       return written;
  57.       }
  58.    total_written += written;
  59.    ptr += written;
  60.    len -= written;
  61.    }
  62.  
  63. return total_written;
  64. }
  65.